package com.crane.oss.web.controller.school;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.dto.SingleResponse;
import com.crane.oss.school.bean.request.task.QueryStudentTaskDetailListReq;
import com.crane.oss.school.bean.request.task.QueryTaskDetailRopeListReq;
import com.crane.oss.school.bean.request.task.QueryTaskRopeListReq;
import com.crane.oss.school.bean.resp.*;
import com.crane.oss.school.service.TaskService;
import com.crane.oss.web.BaseBusinessController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@Api(value = "TeachCourseController", tags = {"任务-跳绳"})
@RestController
@RequestMapping("/task/rope")
public class TaskSkipRopeController extends BaseBusinessController {

    @Resource
    TaskService taskService;


    @ApiOperation(value = "跳绳首页", notes = "跳绳首页")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryTaskRopeListReq")
    @PostMapping("/list")
    public SingleResponse<Map<String, List<TaskRopeWebResp>>> queryTaskRopeList(@RequestBody QueryTaskRopeListReq request) {
        request.setPartyId(getPartyId());
        request.setPageSize(1000);
        if(request.getEndTime().after(new Date())){
            request.setEndTime(new Date());
        }
        return SingleResponse.of(taskService.queryTaskRopeList(request));
    }


    @ApiOperation(value = "查询任务详情", notes = "查询任务详情")
    @ApiImplicitParam(name = "taskId", value = "任务id", paramType = "path", dataType = "Long")
    @GetMapping("/detail/{taskId}")
    public SingleResponse<TaskResp> queryTaskDetail(@PathVariable("taskId") Long taskId) {
        return SingleResponse.of(taskService.queryTaskDetail(taskId));
    }

    @ApiOperation(value = "任务人员列表", notes = "任务人员提交列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryTaskDetailRopeListReq")
    @PostMapping("/studentList")
    public MultiResponse<TaskRopeStudentResp> queryTaskDetailRopeList(@RequestBody QueryTaskDetailRopeListReq request) {
        IPage<TaskRopeStudentResp> page = taskService.queryTaskDetailRopeList(request);
        return MultiResponse.of(page);
    }

    @ApiOperation(value = "学生历史统计数据", notes = "学生历史统计数据")
    @ApiImplicitParam(name = "studentId", value = "学生id", paramType = "path", dataType = "Long")
    @GetMapping("/totalHistory/{studentId}")
    public SingleResponse<TotalSkipRopeResp> totalHistory(@PathVariable("studentId") Long studentId) {
        return SingleResponse.of(taskService.queryTotalSkipRope(studentId));
    }

    @ApiOperation(value = "学生历史提交任务列表", notes = "学生提交任务列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryStudentTaskDetailListReq")
    @PostMapping("/studentRopeList")
    public MultiResponse<TaskStudentSkipRopeResp> list(@RequestBody QueryStudentTaskDetailListReq request) {
        IPage<TaskStudentSkipRopeResp> page = taskService.queryStudentTaskDetailList(request);
        return MultiResponse.of(page);
    }

}
